package org.wen.soft.generate.model;

import lombok.Data;
import org.wen.soft.generate.util.GStrUtil;

/**
 * 方法可访问变量信息
 */
@Data
public class GeneMethodVariable {
    String name;
    String descriptorSimpleName;
    String descriptorClassName;
    String signatureSimpleName;
    String signatureClassName;
    String type;     // field、parameter、 invoke_parameter、invoke_return、invoke_new

    public GeneMethodVariable() {
    }

    /**
     * 成员变量构建
     */
    public GeneMethodVariable(GeneField field) {
        this.signatureClassName = field.getSignatureClassName();
        this.signatureSimpleName = field.getSignatureClassSimpleName();
        this.descriptorClassName = field.getDescriptorClassName();
        this.descriptorSimpleName = field.getDescriptorSimpleName();
        this.type = "field";
        this.name = field.getName();
    }

    /**
     * 方法返回值构建（invoke）
     */
    public GeneMethodVariable(GeneMethod method) {
        this.signatureClassName = method.getReturnSignatureClassName();
        this.signatureSimpleName = method.getReturnSignatureSimpleName();
        this.descriptorClassName = method.getReturnDescriptorClassName();
        this.descriptorSimpleName = method.getReturnDescriptorSimpleName();
        this.type = "invoke_return";
        this.name = GStrUtil.varName(descriptorSimpleName);

    }


}
